package com.example.springdemo;

import com.example.springdemo.aop.UserDao;
import com.example.springdemo.aop.UserImpl;
import com.example.springdemo.bean.Customer;
import com.example.springdemo.bean.CustomerByAnno;
import com.example.springdemo.bean.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@SpringBootApplication
public class SpringdemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringdemoApplication.class, args);

//        ApplicationContext context = new ClassPathXmlApplicationContext("appContext.xml");
        //基于setter方式的注入
//        Customer customer = (Customer) context.getBean("cu");
//        System.out.println("id =" +customer.getId() + "username = " +
//                customer.getUsername() + "password=" + customer.getPassword());

//        基于构造器方式注入
//        Customer customer = (Customer) context.getBean("cu2");
//        System.out.println("id=" + customer.getId() + " username =" + customer.getUsername() +
//                " password=" + customer.getPassword());

//        ApplicationContext con = new AnnotationConfigApplicationContext(MyConfig.class);
//        CustomerByAnno anno = con.getBean(CustomerByAnno.class);
//        System.out.println("id = " + anno.getId() + " username=" + anno.getUsername() +
//                " password=" + anno.getPassword());

        ApplicationContext context1 = new ClassPathXmlApplicationContext("aopXml.xml");
        UserDao userDao= (UserDao) context1.getBean("userImpl");
        userDao.addUser();


    }

}
